package com.joysuch.wwyt.bp.controller;

import com.joysuch.wwyt.bp.bean.BpDeviceFacilityCheckRecordBean;
import com.joysuch.wwyt.bp.entity.BpDeviceFacilityCheckRecord;
import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.core.service.BpDeviceFacilityCheckRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bp/device-facility-check-record")
@Api(tags = "设备设施管理-设备检查")
public class BpDeviceFacilityCheckRecordController {

    @Autowired
    private BpDeviceFacilityCheckRecordService service;

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public ResultBean save(@RequestBody BpDeviceFacilityCheckRecordBean bean) {
        BpDeviceFacilityCheckRecord record = service.save(bean);
        return ResultBean.success(record);
    }

    @GetMapping("/getById")
    @ApiOperation(value = "查看")
    public ResultBean getById(Long id) {
        BpDeviceFacilityCheckRecordBean bean = service.getById(id);
        return ResultBean.success(bean);
    }

    @GetMapping("/deleteById")
    @ApiOperation(value = "删除记录")
    public ResultBean deleteById(Long recordId) {
        if (recordId == null || recordId <= 0) {
            return ResultBean.wrapErrorResultDefault("出现了一点小错误，请稍后重试！");
        }
        service.deleteById(recordId);
        return ResultBean.success("");
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页")
    public ResultBean page(Pageable page, Long deviceFacilityId) {
        Page<BpDeviceFacilityCheckRecordBean> p = service.page(page, deviceFacilityId);
        return ResultBean.pageData(p.getContent(), p.getTotalElements());
    }
}
